Editors exist that enable users to create and modify structured documents. For example, HyperText Markup Language (HTML) editors, Cascading Style Sheet (CSS) editors and Extensible Markup Language (XML) editors exist that enable users to create and modify documents in which elements can be embedded within other elements, thereby forming a tree-like structure. Some of these editors provide a user with an option to “validate” or “check” a document for potential syntactic and/or semantic errors. Often, the aforementioned error checking process is performed while the user is typing and errors identified by the process are displayed directly in the document using visual indicators such as underlining or squiggles.
When a document is large, the process of syntactic and/or semantic error checking may take a long time. The error checking is typically implemented as a background process that is performed either as part of a main application thread that is used to manage the editor's user interface (UI) or in a separate background thread. In a case in which the error checking is performed as part of the main application thread, such error checking must be performed during idle times when the user has stopped changing the document. Such a “check on idle” approach can block the main application thread, thereby making the editor appear sluggish.
If the error checking is performed in a background thread that is separate from the main application thread, the background thread may end up checking a document that is out of date. This is because the user may make changes to the document subsequent to the time when the background thread was started. As a result, the background thread may identify errors for document elements that have already been deleted. Furthermore, the position of various elements and attributes within the document may change as the user implements edits on the main application thread. Consequently, it may be difficult for the background thread to track where to display a visual indicator corresponding to an element or attribute that has been identified as erroneous. In addition, many graphical systems only permit UI updates to be handled by the main application thread which presents additional difficulties when a background thread is used for error checking.
Regardless of whether error checking is performed on a main application thread or a separate background thread, checking the complete document in the background after every change is inefficient and wastes a lot of central processing unit (CPU) cycles.